package edu.syr.iis.web.model;

import java.util.Comparator;

public class DialogueActComparator implements Comparator<DialogueAct> {

	public int compare(DialogueAct da1, DialogueAct da2) {

		if (da1.getMessage() != null && da2.getMessage() != null)
		{
			if (da1.getMessage().getMessageId() < da2.getMessage().getMessageId())
				return -1;
		
			else if (da1.getMessage().getMessageId() > da2.getMessage().getMessageId())
				return 1;
		}
		
		if (da1.getUser().getUserId() < da2.getUser().getUserId())
			return -1;
		
		if (da1.getStartIndex() < da2.getStartIndex())
			return -1;
			
		else if (da1.getStartIndex() > da2.getStartIndex())
			return 1;
			
		else if (da1.getEndIndex() < da2.getEndIndex())
			return -1;
			
		else if (da1.getEndIndex() > da2.getEndIndex())
			return 1;

		else if (da1.getDialogueActId() < da2.getDialogueActId())
			return -1;
			
		else if (da1.getDialogueActId() > da2.getDialogueActId())
			return 1;
		
		if (da1.getAdjacentDialogueAct() != null && da2.getAdjacentDialogueAct() != null)
		{
			if (da1.getAdjacentDialogueAct().getDialogueActId() < da2.getAdjacentDialogueAct().getDialogueActId())
				return -1;
			
			else if (da1.getAdjacentDialogueAct().getDialogueActId() > da2.getAdjacentDialogueAct().getDialogueActId())
				return 1;
		
			else if (da1.getAdjacency().getAdjacencyId() < da2.getAdjacency().getAdjacencyId())
				return -1;
			
			else if (da1.getAdjacency().getAdjacencyId() > da2.getAdjacency().getAdjacencyId())
				return 1;
		}
		
		return -1;
	}
}
